<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>持明法洲登录页面</title>
		<link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
		 <link rel="stylesheet" href="${pageContext.request.contextPath}/css/main.css"  media="all">
		 <link rel="stylesheet" href="${pageContext.request.contextPath}/css/plugins/font-awesome-4.7.0/css/font-awesome.min.css"  media="all">
		<script src="${pageContext.request.contextPath}/layui/layui.js" type="text/javascript"></script>

	</head>
	<body class="layui-layout-body">


		<table id="demo" lay-filter="test"></table>
		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		</script>
		<script>
			layui.use(['table','layer'], function(){
				var table = layui.table;
				var layer = layui.layer;
				var $ = layui.$;
				//第一个实例
				table.render({
					elem: '#demo'
					,height: 500
					,url: '${pageContext.request.contextPath}/user/selectAll' //数据接口
					,page: true //开启分页
					,cols: [[ //表头
						{field: 'id', title: 'ID', width:80}
						,{field: 'telphone', title: '电话', width:150}
						,{field: 'password', title: '密码', width:80}
						,{field: 'image', title: '头像', width:80,templet: function(d){
								return '<img src="/cmfz/'+d.image+'"/>'
							}}
						,{field: 'nickName', title: '昵称', width:80}
						,{field: 'name', title: '姓名', width:80}
						,{field: 'sex', title: '性别', width:80}
						,{field: 'autograph', title: '个性签名', width:80}
						,{field: 'province', title: '省份', width: 177}
						,{field: 'city', title: '城市', width: 80}
						,{field: 'guruId', title: '上师姓名', width: 80,templet: function(d){
								return '<span>'+d.g.name+'</span>'
							}}
						,{field: 'status', title: '状态', width: 80}
						,{field: 'createDate', title: '注册时间', width: 135}
						,{fixed: 'right', title: '操作', width: 135, toolbar: '#barDemo'}
					]]
				});
				table.on('tool(test)', function(obj){
					var data = obj.data; //获得当前行数据
					var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
					console.log(data)
					if(layEvent === 'edit'){ //编辑
								layer.msg("操作成功");
						$.ajax({
							url:'/cmfz/user/status'
							,data:'id='+data.id+"&status="+data.status
							,success:function () {
								table.reload('demo', {
									url: '/cmfz/selectAll/selectAll'
								});
							}
						})
					}
				});
			});
		</script>
	</body>
</html>
